'use strict';

const dayjs = require('dayjs');
const Subscription = require('egg').Subscription;

// 每日大姨妈提醒
class YzxMensesCache extends Subscription {
  static get schedule() {
    return {
      // interval: '5s',
      type: 'worker',
      cron: '0 0 22 * * *',
    };
  }
  async base_subscribe({ name, content }) {
    await this.service.mailer.send({
      emails: ['2428047022@qq.com'],
      subject: `定时提醒-${name}`,
      html: content,
    });
  }
  async subscribe() {
    const date_menses = dayjs('2022-6-25');
    const format = 'YYYY-MM-DD';
    const date_now = dayjs();
    const cnt = date_now.diff(date_menses, 'day');
    if (cnt >= 25) {
      await this.base_subscribe({
        name: '大姨妈提醒',
        content: `距离上一次大姨妈(${date_menses.format(format)})已有${cnt}天。`,
      });
    }
  }
}

module.exports = YzxMensesCache;
